/* 
	数据存储方法:
		1.cookie存取方法 cookie
*/	

// cookie 操作
const cookie = {
    // 新增、修改：参数分别是cookie的名称，cookie的值，cookie的有效时间
    set: function (key, value, time) {
      let date = new Date()
      let expiresDays = time
      date.setTime(date.getTime() + expiresDays * 24 * 3600 * 1000)
      // 这里是添加到已有的cookie中， 不要弄成+=
      document.cookie = key + '=' + value + ';path=/;expiress=' + date.toTimeString()
    },
	// 获取
    get: function (key) {
      let getCookie = document.cookie.replace(/[ ]/g, '')
      let arrCookie = getCookie.split(';')
      let tips
      for (let i = 0; i != arrCookie.length; i++) {
        let arr = arrCookie[i].split('=')
        if (key == arr[0]) {
          tips = arr[1]
          break
        }
      }
      return tips
    },
	// 删除
    delete: function (key) {
      let date = new Date()
      date.setTime(date.getTime() - 10000000)
      document.cookie = key + '= ;path=/;expiress=' + date.toTimeString()
    }
}

export default {
	cookie
}